#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>

using namespace std;

struct ListNode
{
	int val;
	struct ListNode* next;
	ListNode(int x) : val(x), next(nullptr) {}
};

ListNode* ReverseList(ListNode* head)
{
	ListNode* n1 = nullptr, * n2 = head, * n3 = head->next;
	
	while (n2)
	{
		n2->next = n1;
		n1 = n2;
		n2 = n3;
		if (n3)
		{
			n3 = n3->next;
		}
	}

	return n1;
}

int main()
{
	ListNode* node1 = new ListNode(1);
	ListNode* node2 = new ListNode(2);
	ListNode* node3 = new ListNode(3);

	node1->next = node2;
	node2->next = node3;

	ListNode* ret = ReverseList(node1);
	while (ret)
	{
		cout << ret->val << ' ';
		ret = ret->next;
	}

	return 0;
}